

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>7.6. Homogeneous Transformation Matrices and Quaternions — MDAnalysis.core.transformations &mdash; MDAnalysis v0.7.5-devel documentation</title>
    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.7.5-devel',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within MDAnalysis v0.7.5-devel documentation"
          href="../../_static/opensearch.xml"/>
    <link rel="shortcut icon" href="../../_static/mdanalysis-logo.ico"/>
    <link rel="top" title="MDAnalysis v0.7.5-devel documentation" href="../../index.html" />
    <link rel="up" title="7. Core modules" href="../core_modules.html" />
    <link rel="next" title="7.7. Fast QCP RMSD structure alignment — MDAnalysis.core.qcprot" href="qcprot.html" />
    <link rel="prev" title="7.5. Fast distance array computation — MDAnalysis.core.distances" href="distances.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="qcprot.html" title="7.7. Fast QCP RMSD structure alignment — MDAnalysis.core.qcprot"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="distances.html" title="7.5. Fast distance array computation — MDAnalysis.core.distances"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../core_modules.html" accesskey="U">7. Core modules</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/mdanalysis-logo-200x150.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">7.6. Homogeneous Transformation Matrices and Quaternions &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.core.transformations</span></tt></a><ul>
<li><a class="reference internal" href="#requirements">7.6.1. Requirements</a></li>
<li><a class="reference internal" href="#notes">7.6.2. Notes</a></li>
<li><a class="reference internal" href="#references">7.6.3. References</a></li>
<li><a class="reference internal" href="#examples">7.6.4. Examples</a></li>
<li><a class="reference internal" href="#functions">7.6.5. Functions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="distances.html"
                        title="previous chapter">7.5. Fast distance array computation &#8212; <tt class="docutils literal docutils literal docutils literal"><span class="pre">MDAnalysis.core.distances</span></tt></a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="qcprot.html"
                        title="next chapter">7.7. Fast QCP RMSD structure alignment &#8212; <tt class="docutils literal docutils literal"><span class="pre">MDAnalysis.core.qcprot</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/documentation_pages/core/transformations.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-MDAnalysis.core.transformations"></span><div class="section" id="homogeneous-transformation-matrices-and-quaternions-mdanalysis-core-transformations">
<h1>7.6. Homogeneous Transformation Matrices and Quaternions &#8212; <a class="reference internal" href="#module-MDAnalysis.core.transformations" title="MDAnalysis.core.transformations"><tt class="xref py py-mod docutils literal"><span class="pre">MDAnalysis.core.transformations</span></tt></a><a class="headerlink" href="#homogeneous-transformation-matrices-and-quaternions-mdanalysis-core-transformations" title="Permalink to this headline">¶</a></h1>
<p>A library for calculating 4x4 matrices for translating, rotating, reflecting,
scaling, shearing, projecting, orthogonalizing, and superimposing arrays of
3D homogeneous coordinates as well as for converting between rotation matrices,
Euler angles, and quaternions. Also includes an Arcball control object and
functions to decompose transformation matrices.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Authors:</th><td class="field-body"><a class="reference external" href="http://www.lfd.uci.edu/~gohlke/">Christoph Gohlke</a>,
Laboratory for Fluorescence Dynamics, University of California, Irvine</td>
</tr>
<tr class="field"><th class="field-name">Version:</th><td class="field-body">2010.05.10</td>
</tr>
<tr class="field"><th class="field-name">Licence:</th><td class="field-body">BSD 3-clause</td>
</tr>
</tbody>
</table>
<div class="section" id="requirements">
<h2>7.6.1. Requirements<a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><a class="reference external" href="http://www.python.org">Python 2.6 or 3.1</a></li>
<li><a class="reference external" href="http://numpy.scipy.org">Numpy 1.4</a></li>
<li><a class="reference external" href="http://www.lfd.uci.edu/~gohlke/">transformations.c 2010.04.10</a>
(optional implementation of some functions in C)</li>
</ul>
</div>
<div class="section" id="notes">
<h2>7.6.2. Notes<a class="headerlink" href="#notes" title="Permalink to this headline">¶</a></h2>
<p>The API is not stable yet and is expected to change between revisions.</p>
<p>This Python code is not optimized for speed. Refer to the transformations.c
module for a faster implementation of some functions.</p>
<p>Documentation in HTML format can be generated with epydoc.</p>
<p>Matrices (M) can be inverted using numpy.linalg.inv(M), concatenated using
numpy.dot(M0, M1), or used to transform homogeneous coordinates (v) using
numpy.dot(M, v) for shape (4, *) &#8220;point of arrays&#8221;, respectively
numpy.dot(v, M.T) for shape (*, 4) &#8220;array of points&#8221;.</p>
<p>Use the transpose of transformation matrices for OpenGL glMultMatrixd().</p>
<p>Calculations are carried out with numpy.float64 precision.</p>
<p>Vector, point, quaternion, and matrix function arguments are expected to be
&#8220;array like&#8221;, i.e. tuple, list, or numpy arrays.</p>
<p>Return types are numpy arrays unless specified otherwise.</p>
<p>Angles are in radians unless specified otherwise.</p>
<p>Quaternions w+ix+jy+kz are represented as [w, x, y, z].</p>
<p>A triple of Euler angles can be applied/interpreted in 24 ways, which can
be specified using a 4 character string or encoded 4-tuple:</p>
<blockquote>
<div><p><em>Axes 4-string</em>: e.g. &#8216;sxyz&#8217; or &#8216;ryxy&#8217;</p>
<ul class="simple">
<li>first character : rotations are applied to &#8216;s&#8217;tatic or &#8216;r&#8217;otating frame</li>
<li>remaining characters : successive rotation axis &#8216;x&#8217;, &#8216;y&#8217;, or &#8216;z&#8217;</li>
</ul>
<p><em>Axes 4-tuple</em>: e.g. (0, 0, 0, 0) or (1, 1, 1, 1)</p>
<ul class="simple">
<li>inner axis: code of axis (&#8216;x&#8217;:0, &#8216;y&#8217;:1, &#8216;z&#8217;:2) of rightmost matrix.</li>
<li>parity : even (0) if inner axis &#8216;x&#8217; is followed by &#8216;y&#8217;, &#8216;y&#8217; is followed
by &#8216;z&#8217;, or &#8216;z&#8217; is followed by &#8216;x&#8217;. Otherwise odd (1).</li>
<li>repetition : first and last axis are same (1) or different (0).</li>
<li>frame : rotations are applied to static (0) or rotating (1) frame.</li>
</ul>
</div></blockquote>
</div>
<div class="section" id="references">
<h2>7.6.3. References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>
<ol class="arabic simple">
<li>Matrices and transformations. Ronald Goldman.
In &#8220;Graphics Gems I&#8221;, pp 472-475. Morgan Kaufmann, 1990.</li>
<li>More matrices and transformations: shear and pseudo-perspective.
Ronald Goldman. In &#8220;Graphics Gems II&#8221;, pp 320-323. Morgan Kaufmann, 1991.</li>
<li>Decomposing a matrix into simple transformations. Spencer Thomas.
In &#8220;Graphics Gems II&#8221;, pp 320-323. Morgan Kaufmann, 1991.</li>
<li>Recovering the data from the transformation matrix. Ronald Goldman.
In &#8220;Graphics Gems II&#8221;, pp 324-331. Morgan Kaufmann, 1991.</li>
<li>Euler angle conversion. Ken Shoemake.
In &#8220;Graphics Gems IV&#8221;, pp 222-229. Morgan Kaufmann, 1994.</li>
<li>Arcball rotation control. Ken Shoemake.
In &#8220;Graphics Gems IV&#8221;, pp 175-192. Morgan Kaufmann, 1994.</li>
<li>Representing attitude: Euler angles, unit quaternions, and rotation
vectors. James Diebel. 2006.</li>
<li>A discussion of the solution for the best rotation to relate two sets
of vectors. W Kabsch. Acta Cryst. 1978. A34, 827-828.</li>
<li>Closed-form solution of absolute orientation using unit quaternions.
BKP Horn. J Opt Soc Am A. 1987. 4(4):629-642.</li>
<li>Quaternions. Ken Shoemake.
<a class="reference external" href="http://www.sfu.ca/~jwa3/cmpt461/files/quatut.pdf">http://www.sfu.ca/~jwa3/cmpt461/files/quatut.pdf</a></li>
<li>From quaternion to matrix and back. JMP van Waveren. 2005.
<a class="reference external" href="http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm">http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm</a></li>
<li>Uniform random rotations. Ken Shoemake.
In &#8220;Graphics Gems III&#8221;, pp 124-132. Morgan Kaufmann, 1992.</li>
<li>Quaternion in molecular modeling. CFF Karney.
J Mol Graph Mod, 25(5):595-604</li>
<li>New method for extracting the quaternion from a rotation matrix.
Itzhack Y Bar-Itzhack, J Guid Contr Dynam. 2000. 23(6): 1085-1087.</li>
</ol>
</div>
<div class="section" id="examples">
<h2>7.6.4. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">gamma</span> <span class="o">=</span> <span class="mf">0.123</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.234</span><span class="p">,</span> <span class="mf">2.345</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">origin</span><span class="p">,</span> <span class="n">xaxis</span><span class="p">,</span> <span class="n">yaxis</span><span class="p">,</span> <span class="n">zaxis</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">identity_matrix</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rx</span> <span class="o">=</span> <span class="n">rotation_matrix</span><span class="p">(</span><span class="n">alpha</span><span class="p">,</span> <span class="n">xaxis</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Ry</span> <span class="o">=</span> <span class="n">rotation_matrix</span><span class="p">(</span><span class="n">beta</span><span class="p">,</span> <span class="n">yaxis</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rz</span> <span class="o">=</span> <span class="n">rotation_matrix</span><span class="p">(</span><span class="n">gamma</span><span class="p">,</span> <span class="n">zaxis</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">concatenate_matrices</span><span class="p">(</span><span class="n">Rx</span><span class="p">,</span> <span class="n">Ry</span><span class="p">,</span> <span class="n">Rz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">euler</span> <span class="o">=</span> <span class="n">euler_from_matrix</span><span class="p">(</span><span class="n">R</span><span class="p">,</span> <span class="s">&#39;rxyz&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">([</span><span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">gamma</span><span class="p">],</span> <span class="n">euler</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Re</span> <span class="o">=</span> <span class="n">euler_matrix</span><span class="p">(</span><span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">gamma</span><span class="p">,</span> <span class="s">&#39;rxyz&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">R</span><span class="p">,</span> <span class="n">Re</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">al</span><span class="p">,</span> <span class="n">be</span><span class="p">,</span> <span class="n">ga</span> <span class="o">=</span> <span class="n">euler_from_matrix</span><span class="p">(</span><span class="n">Re</span><span class="p">,</span> <span class="s">&#39;rxyz&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">Re</span><span class="p">,</span> <span class="n">euler_matrix</span><span class="p">(</span><span class="n">al</span><span class="p">,</span> <span class="n">be</span><span class="p">,</span> <span class="n">ga</span><span class="p">,</span> <span class="s">&#39;rxyz&#39;</span><span class="p">))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">qx</span> <span class="o">=</span> <span class="n">quaternion_about_axis</span><span class="p">(</span><span class="n">alpha</span><span class="p">,</span> <span class="n">xaxis</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">qy</span> <span class="o">=</span> <span class="n">quaternion_about_axis</span><span class="p">(</span><span class="n">beta</span><span class="p">,</span> <span class="n">yaxis</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">qz</span> <span class="o">=</span> <span class="n">quaternion_about_axis</span><span class="p">(</span><span class="n">gamma</span><span class="p">,</span> <span class="n">zaxis</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">quaternion_multiply</span><span class="p">(</span><span class="n">qx</span><span class="p">,</span> <span class="n">qy</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">quaternion_multiply</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="n">qz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rq</span> <span class="o">=</span> <span class="n">quaternion_matrix</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">R</span><span class="p">,</span> <span class="n">Rq</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span> <span class="o">=</span> <span class="n">scale_matrix</span><span class="p">(</span><span class="mf">1.23</span><span class="p">,</span> <span class="n">origin</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">translation_matrix</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">shear_matrix</span><span class="p">(</span><span class="n">beta</span><span class="p">,</span> <span class="n">xaxis</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">zaxis</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">random_rotation_matrix</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">concatenate_matrices</span><span class="p">(</span><span class="n">T</span><span class="p">,</span> <span class="n">R</span><span class="p">,</span> <span class="n">Z</span><span class="p">,</span> <span class="n">S</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">scale</span><span class="p">,</span> <span class="n">shear</span><span class="p">,</span> <span class="n">angles</span><span class="p">,</span> <span class="n">trans</span><span class="p">,</span> <span class="n">persp</span> <span class="o">=</span> <span class="n">decompose_matrix</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">scale</span><span class="p">,</span> <span class="mf">1.23</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">trans</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">shear</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">math</span><span class="o">.</span><span class="n">tan</span><span class="p">(</span><span class="n">beta</span><span class="p">),</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">R</span><span class="p">,</span> <span class="n">euler_matrix</span><span class="p">(</span><span class="n">axes</span><span class="o">=</span><span class="s">&#39;sxyz&#39;</span><span class="p">,</span> <span class="o">*</span><span class="n">angles</span><span class="p">))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M1</span> <span class="o">=</span> <span class="n">compose_matrix</span><span class="p">(</span><span class="n">scale</span><span class="p">,</span> <span class="n">shear</span><span class="p">,</span> <span class="n">angles</span><span class="p">,</span> <span class="n">trans</span><span class="p">,</span> <span class="n">persp</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</div>
<div class="section" id="functions">
<h2>7.6.5. Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="MDAnalysis.core.transformations.Arcball">
<em class="property">class </em><tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">Arcball</tt><big>(</big><em>initial=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball" title="Permalink to this definition">¶</a></dt>
<dd><p>Virtual Trackball Control.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span> <span class="o">=</span> <span class="n">Arcball</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span> <span class="o">=</span> <span class="n">Arcball</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="n">numpy</span><span class="o">.</span><span class="n">identity</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">place</span><span class="p">([</span><span class="mi">320</span><span class="p">,</span> <span class="mi">320</span><span class="p">],</span> <span class="mi">320</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">down</span><span class="p">([</span><span class="mi">500</span><span class="p">,</span> <span class="mi">250</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">drag</span><span class="p">([</span><span class="mi">475</span><span class="p">,</span> <span class="mi">275</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">ball</span><span class="o">.</span><span class="n">matrix</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">R</span><span class="p">),</span> <span class="mf">3.90583455</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span> <span class="o">=</span> <span class="n">Arcball</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">place</span><span class="p">([</span><span class="mi">320</span><span class="p">,</span> <span class="mi">320</span><span class="p">],</span> <span class="mi">320</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">setaxes</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">setconstrain</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">down</span><span class="p">([</span><span class="mi">400</span><span class="p">,</span> <span class="mi">200</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">drag</span><span class="p">([</span><span class="mi">200</span><span class="p">,</span> <span class="mi">400</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">ball</span><span class="o">.</span><span class="n">matrix</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">R</span><span class="p">),</span> <span class="mf">0.2055924</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ball</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
</pre></div>
</div>
<p>Initialize virtual trackball control.</p>
<p>initial : quaternion or rotation matrix</p>
<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.down">
<tt class="descname">down</tt><big>(</big><em>point</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.down" title="Permalink to this definition">¶</a></dt>
<dd><p>Set initial cursor window coordinates and pick constrain-axis.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.drag">
<tt class="descname">drag</tt><big>(</big><em>point</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.drag" title="Permalink to this definition">¶</a></dt>
<dd><p>Update current cursor window coordinates.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.getconstrain">
<tt class="descname">getconstrain</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.getconstrain" title="Permalink to this definition">¶</a></dt>
<dd><p>Return state of constrain to axis mode.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.matrix">
<tt class="descname">matrix</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return homogeneous rotation matrix.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.next">
<tt class="descname">next</tt><big>(</big><em>acceleration=0.0</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.next" title="Permalink to this definition">¶</a></dt>
<dd><p>Continue rotation in direction of last drag.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.place">
<tt class="descname">place</tt><big>(</big><em>center</em>, <em>radius</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.place" title="Permalink to this definition">¶</a></dt>
<dd><p>Place Arcball, e.g. when window size changes.</p>
<dl class="docutils">
<dt>center <span class="classifier-delimiter">:</span> <span class="classifier">sequence[2]</span></dt>
<dd>Window coordinates of trackball center.</dd>
<dt>radius <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd>Radius of trackball in window coordinates.</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.setaxes">
<tt class="descname">setaxes</tt><big>(</big><em>*axes</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.setaxes" title="Permalink to this definition">¶</a></dt>
<dd><p>Set axes to constrain rotations.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.core.transformations.Arcball.setconstrain">
<tt class="descname">setconstrain</tt><big>(</big><em>constrain</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.Arcball.setconstrain" title="Permalink to this definition">¶</a></dt>
<dd><p>Set state of constrain to axis mode.</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.arcball_nearest_axis">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">arcball_nearest_axis</tt><big>(</big><em>point</em>, <em>axes</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.arcball_nearest_axis" title="Permalink to this definition">¶</a></dt>
<dd><p>Return axis, which arc is nearest to point.</p>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.compose_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">compose_matrix</tt><big>(</big><em>scale=None</em>, <em>shear=None</em>, <em>angles=None</em>, <em>translate=None</em>, <em>perspective=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.compose_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return transformation matrix from sequence of transformations.</p>
<p>This is the inverse of the decompose_matrix function.</p>
<dl class="docutils">
<dt>Sequence of transformations:</dt>
<dd>scale : vector of 3 scaling factors
shear : list of shear factors for x-y, x-z, y-z axes
angles : list of Euler angles about static x, y, z axes
translate : translation vector along x, y, z axes
perspective : perspective partition of matrix</dd>
</dl>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">scale</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">shear</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">angles</span> <span class="o">=</span> <span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">trans</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">persp</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M0</span> <span class="o">=</span> <span class="n">compose_matrix</span><span class="p">(</span><span class="n">scale</span><span class="p">,</span> <span class="n">shear</span><span class="p">,</span> <span class="n">angles</span><span class="p">,</span> <span class="n">trans</span><span class="p">,</span> <span class="n">persp</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">decompose_matrix</span><span class="p">(</span><span class="n">M0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M1</span> <span class="o">=</span> <span class="n">compose_matrix</span><span class="p">(</span><span class="o">*</span><span class="n">result</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">M0</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.concatenate_matrices">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">concatenate_matrices</tt><big>(</big><em>*matrices</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.concatenate_matrices" title="Permalink to this definition">¶</a></dt>
<dd><p>Return concatenation of series of transformation matrices.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">concatenate_matrices</span><span class="p">(</span><span class="n">M</span><span class="p">))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">M</span><span class="o">.</span><span class="n">T</span><span class="p">),</span> <span class="n">concatenate_matrices</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">M</span><span class="o">.</span><span class="n">T</span><span class="p">))</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.decompose_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">decompose_matrix</tt><big>(</big><em>matrix</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.decompose_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return sequence of transformations from transformation matrix.</p>
<dl class="docutils">
<dt>matrix <span class="classifier-delimiter">:</span> <span class="classifier">array_like</span></dt>
<dd>Non-degenerative homogeneous transformation matrix</dd>
<dt>Return tuple of:</dt>
<dd>scale : vector of 3 scaling factors
shear : list of shear factors for x-y, x-z, y-z axes
angles : list of Euler angles about static x, y, z axes
translate : translation vector along x, y, z axes
perspective : perspective partition of matrix</dd>
</dl>
<p>Raise ValueError if matrix is of wrong type or degenerative.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">T0</span> <span class="o">=</span> <span class="n">translation_matrix</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">scale</span><span class="p">,</span> <span class="n">shear</span><span class="p">,</span> <span class="n">angles</span><span class="p">,</span> <span class="n">trans</span><span class="p">,</span> <span class="n">persp</span> <span class="o">=</span> <span class="n">decompose_matrix</span><span class="p">(</span><span class="n">T0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T1</span> <span class="o">=</span> <span class="n">translation_matrix</span><span class="p">(</span><span class="n">trans</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">T0</span><span class="p">,</span> <span class="n">T1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span> <span class="o">=</span> <span class="n">scale_matrix</span><span class="p">(</span><span class="mf">0.123</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">scale</span><span class="p">,</span> <span class="n">shear</span><span class="p">,</span> <span class="n">angles</span><span class="p">,</span> <span class="n">trans</span><span class="p">,</span> <span class="n">persp</span> <span class="o">=</span> <span class="n">decompose_matrix</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">scale</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">0.123</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R0</span> <span class="o">=</span> <span class="n">euler_matrix</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">scale</span><span class="p">,</span> <span class="n">shear</span><span class="p">,</span> <span class="n">angles</span><span class="p">,</span> <span class="n">trans</span><span class="p">,</span> <span class="n">persp</span> <span class="o">=</span> <span class="n">decompose_matrix</span><span class="p">(</span><span class="n">R0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R1</span> <span class="o">=</span> <span class="n">euler_matrix</span><span class="p">(</span><span class="o">*</span><span class="n">angles</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">R0</span><span class="p">,</span> <span class="n">R1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.euler_from_quaternion">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">euler_from_quaternion</tt><big>(</big><em>quaternion</em>, <em>axes='sxyz'</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.euler_from_quaternion" title="Permalink to this definition">¶</a></dt>
<dd><p>Return Euler angles from quaternion for specified axis sequence.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">angles</span> <span class="o">=</span> <span class="n">euler_from_quaternion</span><span class="p">([</span><span class="mf">0.99810947</span><span class="p">,</span> <span class="mf">0.06146124</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">angles</span><span class="p">,</span> <span class="p">[</span><span class="mf">0.123</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.projection_from_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">projection_from_matrix</tt><big>(</big><em>matrix</em>, <em>pseudo=False</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.projection_from_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return projection plane and perspective point from projection matrix.</p>
<p>Return values are same as arguments for projection_matrix function:
point, normal, direction, perspective, and pseudo.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">point</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">normal</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">direct</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">persp</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P0</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">normal</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">projection_from_matrix</span><span class="p">(</span><span class="n">P0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="o">*</span><span class="n">result</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">P0</span><span class="p">,</span> <span class="n">P1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P0</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">normal</span><span class="p">,</span> <span class="n">direct</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">projection_from_matrix</span><span class="p">(</span><span class="n">P0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="o">*</span><span class="n">result</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">P0</span><span class="p">,</span> <span class="n">P1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P0</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">normal</span><span class="p">,</span> <span class="n">perspective</span><span class="o">=</span><span class="n">persp</span><span class="p">,</span> <span class="n">pseudo</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">projection_from_matrix</span><span class="p">(</span><span class="n">P0</span><span class="p">,</span> <span class="n">pseudo</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="o">*</span><span class="n">result</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">P0</span><span class="p">,</span> <span class="n">P1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P0</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">normal</span><span class="p">,</span> <span class="n">perspective</span><span class="o">=</span><span class="n">persp</span><span class="p">,</span> <span class="n">pseudo</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">projection_from_matrix</span><span class="p">(</span><span class="n">P0</span><span class="p">,</span> <span class="n">pseudo</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span> <span class="o">=</span> <span class="n">projection_matrix</span><span class="p">(</span><span class="o">*</span><span class="n">result</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">P0</span><span class="p">,</span> <span class="n">P1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.quaternion_imag">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">quaternion_imag</tt><big>(</big><em>quaternion</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.quaternion_imag" title="Permalink to this definition">¶</a></dt>
<dd><p>Return imaginary part of quaternion.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">quaternion_imag</span><span class="p">([</span><span class="mf">3.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">])</span>
<span class="go">[0.0, 1.0, 2.0]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.quaternion_real">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">quaternion_real</tt><big>(</big><em>quaternion</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.quaternion_real" title="Permalink to this definition">¶</a></dt>
<dd><p>Return real part of quaternion.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">quaternion_real</span><span class="p">([</span><span class="mf">3.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">])</span>
<span class="go">3.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.reflection_from_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">reflection_from_matrix</tt><big>(</big><em>matrix</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.reflection_from_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return mirror plane point and normal vector from reflection matrix.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">v0</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M0</span> <span class="o">=</span> <span class="n">reflection_matrix</span><span class="p">(</span><span class="n">v0</span><span class="p">,</span> <span class="n">v1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">point</span><span class="p">,</span> <span class="n">normal</span> <span class="o">=</span> <span class="n">reflection_from_matrix</span><span class="p">(</span><span class="n">M0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M1</span> <span class="o">=</span> <span class="n">reflection_matrix</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">normal</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">M0</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.rotation_from_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">rotation_from_matrix</tt><big>(</big><em>matrix</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.rotation_from_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return rotation angle and axis from rotation matrix.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">angle</span> <span class="o">=</span> <span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span> <span class="o">-</span> <span class="mf">0.5</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">direc</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">point</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R0</span> <span class="o">=</span> <span class="n">rotation_matrix</span><span class="p">(</span><span class="n">angle</span><span class="p">,</span> <span class="n">direc</span><span class="p">,</span> <span class="n">point</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">angle</span><span class="p">,</span> <span class="n">direc</span><span class="p">,</span> <span class="n">point</span> <span class="o">=</span> <span class="n">rotation_from_matrix</span><span class="p">(</span><span class="n">R0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R1</span> <span class="o">=</span> <span class="n">rotation_matrix</span><span class="p">(</span><span class="n">angle</span><span class="p">,</span> <span class="n">direc</span><span class="p">,</span> <span class="n">point</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">R0</span><span class="p">,</span> <span class="n">R1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.rotaxis">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">rotaxis</tt><big>(</big><em>a</em>, <em>b</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.rotaxis" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the rotation axis to rotate vector a into b.</p>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.scale_from_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">scale_from_matrix</tt><big>(</big><em>matrix</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.scale_from_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return scaling factor, origin and direction from scaling matrix.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">-</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">origin</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">direct</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S0</span> <span class="o">=</span> <span class="n">scale_matrix</span><span class="p">(</span><span class="n">factor</span><span class="p">,</span> <span class="n">origin</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">direction</span> <span class="o">=</span> <span class="n">scale_from_matrix</span><span class="p">(</span><span class="n">S0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span> <span class="o">=</span> <span class="n">scale_matrix</span><span class="p">(</span><span class="n">factor</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">direction</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">S0</span><span class="p">,</span> <span class="n">S1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S0</span> <span class="o">=</span> <span class="n">scale_matrix</span><span class="p">(</span><span class="n">factor</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">direct</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">direction</span> <span class="o">=</span> <span class="n">scale_from_matrix</span><span class="p">(</span><span class="n">S0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span> <span class="o">=</span> <span class="n">scale_matrix</span><span class="p">(</span><span class="n">factor</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">direction</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">S0</span><span class="p">,</span> <span class="n">S1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.shear_from_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">shear_from_matrix</tt><big>(</big><em>matrix</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.shear_from_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return shear angle, direction and plane from shear matrix.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">angle</span> <span class="o">=</span> <span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span> <span class="o">-</span> <span class="mf">0.5</span><span class="p">)</span> <span class="o">*</span> <span class="mi">4</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">direct</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">point</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">normal</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">direct</span><span class="p">,</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S0</span> <span class="o">=</span> <span class="n">shear_matrix</span><span class="p">(</span><span class="n">angle</span><span class="p">,</span> <span class="n">direct</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">normal</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">angle</span><span class="p">,</span> <span class="n">direct</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">normal</span> <span class="o">=</span> <span class="n">shear_from_matrix</span><span class="p">(</span><span class="n">S0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span> <span class="o">=</span> <span class="n">shear_matrix</span><span class="p">(</span><span class="n">angle</span><span class="p">,</span> <span class="n">direct</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">normal</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_same_transform</span><span class="p">(</span><span class="n">S0</span><span class="p">,</span> <span class="n">S1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.translation_from_matrix">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">translation_from_matrix</tt><big>(</big><em>matrix</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.translation_from_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Return translation vector from translation matrix.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">v0</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">=</span> <span class="n">translation_from_matrix</span><span class="p">(</span><span class="n">translation_matrix</span><span class="p">(</span><span class="n">v0</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">v0</span><span class="p">,</span> <span class="n">v1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.transformations.vecangle">
<tt class="descclassname">MDAnalysis.core.transformations.</tt><tt class="descname">vecangle</tt><big>(</big><em>a</em>, <em>b</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.transformations.vecangle" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the angle between vectors a and b in radians.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="qcprot.html" title="7.7. Fast QCP RMSD structure alignment — MDAnalysis.core.qcprot"
             >next</a> |</li>
        <li class="right" >
          <a href="distances.html" title="7.5. Fast distance array computation — MDAnalysis.core.distances"
             >previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../core_modules.html" >7. Core modules</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2005-2011, Naveen Michaud-Agrawal, Elizabeth J. Denning, Joshua Adelman,
    Christian Beckstein (logo), David Caplan, Jan Domański, Philip Fowler,
    Joseph Goose, Benjamin Hall, Danny Parton, Tyler Reddy, Paul Rigor,
    and Oliver Beckstein.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>